//
//  YSMineDataTool.m
//  Yueshi
//
//  Created by yueshi_tech on 15/7/15.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSMineDataTool.h"

@implementation YSMineDataTool

+(void)registerWithParams:(NSString *)phoneCode password:(NSString *)password success:(void (^)(YSRegisterRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:phoneCode forKey:@"phoneCode"];
    [params setObject:password forKey:@"password"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/register",BASE_URL] param:params hasT:NO resultClass:[YSRegisterRes class] success:success failure:failure];
}

+(void)loginWithParams:(NSString *)phoneCode validateCode:(NSString *)validateCode success:(void (^)(YSRegisterRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:phoneCode forKey:@"phoneCode"];
    [params setObject:validateCode forKey:@"validateCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/login2",BASE_URL] param:params hasT:NO resultClass:[YSRegisterRes class] success:success failure:failure];
}

+(void)forgetWithParams:(NSString *)phoneCode password:(NSString *)password validateCode:(NSString *)validateCode success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:phoneCode forKey:@"phoneCode"];
    [params setObject:password forKey:@"password"];
    [params setObject:validateCode forKey:@"validateCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/resetPassword",BASE_URL] param:params hasT:NO resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)sendCodeWithParams:(NSString *)phoneCode type:(NSInteger)type success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:phoneCode forKey:@"phoneCode"];
    [params setObject:[NSNumber numberWithInteger:type] forKey:@"type"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/registerCode",BASE_URL] param:params hasT:NO resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)oauthLoginWithParam:(NSDictionary *)param success:(void (^)(YSRegisterRes *))success failure:(void (^)(NSError *))failure{
    [self postWithUrl:[NSString stringWithFormat:@"%@user/oauth",BASE_URL] param:param hasT:NO resultClass:[YSRegisterRes class] success:success failure:failure];
}

+(void)getAddressList:(void (^)(YSAddressRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/getAdresList",BASE_URL] param:params hasT:YES resultClass:[YSAddressRes class] success:success failure:failure];
}

+(void)deleteAddressWithID:(NSInteger)adresId success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:adresId] forKey:@"addressId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/addressDel",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)addAddressWithAddressee:(NSString *)addressee phoneCode:(NSString *)phoneCode deliveryId:(NSString *)deliveryId detailAdres:(NSString *)detailAdres postal:(NSString *)postal addressId:(NSInteger)addressId addressStr:(NSString *)addressStr success:(void (^)(YSNewAddressRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:addressee forKey:@"addressee"];
    [params setObject:phoneCode forKey:@"phoneCode"];
    [params setObject:deliveryId forKey:@"deliveryId"];
    [params setObject:detailAdres forKey:@"detailAdres"];
    [params setObject:addressStr forKey:@"addressStr"];
    [params setObject:postal forKey:@"postal"];
    if(addressId != 0){
        [params setObject:[NSNumber numberWithInteger:addressId] forKey:@"addressId"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@user/addressAdd",BASE_URL] param:params hasT:YES resultClass:[YSNewAddressRes class] success:success failure:failure];
}

+(void)setDefaultWithAddressId:(NSInteger)addressId success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:addressId] forKey:@"addressId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/addressDefault",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)getOrderListWithOrderType:(NSInteger)orderType orderCode:(NSString *)orderCode pageIndex:(NSInteger)pageIndex orderStatus:(NSInteger)orderStatus success:(void (^)(YSOrderListRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:orderType] forKey:@"orderType"];
    [params setObject:[NSNumber numberWithInteger:orderStatus] forKey:@"orderStatus"];
    [params setObject:[NSNumber numberWithInteger:pageIndex] forKey:@"pageIndex"];
    if(!ISBLANK(orderCode)){
     [params setObject:orderCode forKey:@"orderCode"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@order/list",BASE_URL] param:params hasT:YES resultClass:[YSOrderListRes class] success:success failure:failure];
}

+(void)getOrderDetailWithOrderCode:(NSString *)orderCode success:(void (^)(YSOrderDetailRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:orderCode forKey:@"orderCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/detail",BASE_URL] param:params hasT:YES resultClass:[YSOrderDetailRes class] success:success failure:failure];
}

+(void)cancleOrderWithOrderCode:(NSString *)orderCode success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:orderCode forKey:@"orderCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/cancel",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)enterWithOrderCode:(NSString *)orderCode success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:orderCode forKey:@"orderCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/confirm",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)getDeliveryWithOrderCode:(NSString *)orderCode success:(void (^)(YSOrderDeliveryRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:orderCode forKey:@"orderCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@order/delivery",BASE_URL] param:params hasT:YES resultClass:[YSOrderDeliveryRes class] success:success failure:failure];
}

+(void)getMineInfo:(NSInteger)orgUserId success:(void (^)(YSRegisterRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    if(orgUserId != 0){
        [params setObject:[NSNumber numberWithInteger:orgUserId] forKey:@"orgUserId"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@user/info",BASE_URL] param:params hasT:YES resultClass:[YSRegisterRes class] success:success failure:failure];
}

+(void)updateUserInfo:(NSString *)imgPath nickName:(NSString *)nickName userGender:(NSInteger)userGender success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    if(!ISBLANK(imgPath)){
      [params setObject:imgPath forKey:@"imgPath"];
    }
    [params setObject:nickName forKey:@"nickName"];
    [params setObject:[NSNumber numberWithInteger:userGender] forKey:@"userGender"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/updateUser",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)getMessageList:(NSInteger )firstId messageType:(NSInteger)messageType success:(void(^)(YSFeedbackRes *result))success failure:(void(^)(NSError *error))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:firstId] forKey:@"firstId"];
    [params setObject:[NSNumber numberWithInteger:messageType] forKey:@"messageType"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/customerServiceList",BASE_URL] param:params hasT:YES resultClass:[YSFeedbackRes class] success:success failure:failure];
}

+(void)sendMessage:(NSString *)content messageType:(NSInteger)messageType success:(void (^)(YSSendMessageRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    if(!ISBLANK(content)){
        [params setObject:content forKey:@"content"];
    }
    [params setObject:[NSNumber numberWithInteger:messageType] forKey:@"messageType"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/ask",BASE_URL] param:params hasT:YES resultClass:[YSSendMessageRes class] success:success failure:failure];
}

+(void)getVoucherInfo:(void (^)(YSVoucherRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/voucherList",BASE_URL] param:params hasT:YES resultClass:[YSVoucherRes class] success:success failure:failure];
}

+(void)validateVoucherWithVoucherCode:(NSString *)voucherCode success:(void (^)(YSValidateVoucherRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:voucherCode forKey:@"voucherCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/validateVoucher",BASE_URL] param:params hasT:YES resultClass:[YSValidateVoucherRes class] success:success failure:failure];
}

+(void)receiveVoucherWithEntityId:(NSString *)entityId success:(void (^)(YSReceiveVoucher *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:entityId forKey:@"entityId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/receiveVoucher",BASE_URL] param:params hasT:YES resultClass:[YSReceiveVoucher class] success:success failure:failure];
}

+(void)getCustomerService:(void (^)(YSCustomerServiceRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@app/selfService",BASE_URL] param:params hasT:NO resultClass:[YSCustomerServiceRes class] success:success failure:failure];
}

+ (void)bindingPhoneWithPhoneCode:(NSString *)phoneCode validateCode:(NSString *)validateCode success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:phoneCode forKey:@"phoneCode"];
    [params setObject:validateCode forKey:@"validateCode"];
    [self postWithUrl:[NSString stringWithFormat:@"%@user/bindingPhone",BASE_URL] param:params hasT:YES resultClass:[YSReceiveVoucher class] success:success failure:failure];
}

@end
